<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class TechnicianResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $data = [
            'id' => $this->id,
            'key' => $this->key,
            'name' => $this->name,
            'short_name' => $this->short_name,
            'avatar' => attachmentUrl($this->avatar),
            'index' => $this->index,
            'province' => $this->province,
            'city' => $this->city,
            'district' => $this->district,
            'background_image' => attachmentUrl($this->background_image),
            'created_at' => createdAt($this->created_at),
            'updated_at' => createdAt($this->updated_at),
            'topic' => new TopicResource($this->whenLoaded('topic')),
            'users_want_appoint_count' => $this->users_want_appoint_count,
            'users_had_appoint_count' => $this->users_had_appoint_count,
        ];

        //关键指标
        $keyIndex = [
            ['label' => '工号', 'value' => $this->short_name],
            ['label' => '指数', 'value' => 666],
            ['label' => '机构', 'value' => '华润'],
        ];
        $data['key_indexes'] = $keyIndex;

        return $data;
    }
}
